package c01_array;

/**
 * leetcode  11
 *
 */
public class S11_2 {
    public static void main(String[] args) {
        S11_2 s11 = new S11_2();
     //   int [] arr = new int[]{1,8,6,2,5,4,8,3,7};
       // int [] arr = new int[]{2,3,4,5,18,17,6};
        int[] arr =new int[15000];
        for (int i = 0; i < 15000; i++) {
            arr[i]=i+1;
        }
        int maxArea = s11.maxArea(arr);
        System.out.println(maxArea);
    }
    public int maxArea(int[] height) {
        int maxArea=0;
        int leftMax = Integer.MIN_VALUE;
        int rightMax = Integer.MIN_VALUE;

        for (int i = 0; i < height.length; i++) {
            if (i>=1&&i<height.length-1&&height[i]<leftMax){
               continue;
            }
            if(leftMax<height[i]) {
                leftMax=height[i];
            }
            rightMax = Integer.MIN_VALUE;
            for(int j = height.length-1;j>i;j--) {

                if (j>=1&&j< height.length-1&&height[j]<rightMax) {
                   continue;
                }
                if(rightMax<height[j]) {
                    rightMax=height[j];
                }
                int currentArea = getArea(height,i,j);
                if(currentArea>maxArea) {
                    maxArea=currentArea;
                }
            }
        }
        return maxArea;
    }


    private int getArea(int[] height, int start,int end) {
        int area = Integer.min(height[start],height[end])*(end-start);
        System.out.println("start:"+height[start]+", end: "+height[end]);
        return area;
    }

}
